# Maintainer: Drew Waranis <drew@waran.is>

_realname=apr
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.5
pkgrel=3
pkgdesc="The Apache Portable Runtime (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://apr.apache.org/"
license=('APACHE')
validpgpkeys=('B1B96F45DFBDCCF974019235193F180AB55D9977')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-libtool"
             "${MINGW_PACKAGE_PREFIX}-python")
source=(https://www.apache.org/dist/apr/${_realname}-${pkgver}.tar.bz2
        'apr_ssize_t.patch'
        'apr_wtypes.patch')
sha256sums=('a67ca9fcf9c4ff59bce7f428a323c8b5e18667fdea7b0ebad47d194371b0a105'
            'ba7d6de7e7930801df483d444b97c159af4ff11b4ce27e1337aea5e0417e6066'
            'b82dd98ec8cff2273fb071dc9f1d2ee7466905c9b82a12d3d83ce1cb5920a5d6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p0 -i ${srcdir}/apr_ssize_t.patch
  patch -p0 -i ${srcdir}/apr_wtypes.patch

  ./buildconf
  # autoreconf -fi
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  # Disable IPv6.
  ../${_realname}-${pkgver}/configure \
    --prefix="${MINGW_PREFIX}" \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --includedir="${MINGW_PREFIX}/include/apr-1" \
    --with-installbuilddir="${MINGW_PREFIX}/share/apr-1/build" \
    --enable-nonportable-atomics \
    --with-devrandom=/dev/urandom \
    --disable-ipv6

  make
}

#check() {
#  cd "${srcdir}/build-${MINGW_CHOST}"
#  make -j1 check
#}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
